package com.idbk.chargestation.activity.assist;


import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.idbk.chargestation.R;
import com.idbk.chargestation.base.BaseActivity;

/**
 * 关于我们
 *
 * @author lupc
 */
public class ActivityAbout extends BaseActivity implements OnClickListener {

    private TextView mTexHelp;
    private int mClickCount = 7;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_about);

        setupView();
    }

    @SuppressWarnings("ConstantConditions")
    private void setupView() {
        //setupToolBar2();//显示标题栏
        findViewById(R.id.toolbar_back).setOnClickListener(this);
        findViewById(R.id.textview_share).setOnClickListener(this);
        findViewById(R.id.textview_introduction).setOnClickListener(this);
        mTexHelp = (TextView) findViewById(R.id.textview_help);
        if (mTexHelp != null) {
            mTexHelp.setOnClickListener(this);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.textview_share:
                Intent intentShare = new Intent(ActivityAbout.this, ActivityQrCode.class);
                startActivity(intentShare);
                break;

            case R.id.textview_introduction:
                Intent intentInt = new Intent(ActivityAbout.this, ActivityIntroduction.class);
                startActivity(intentInt);
                break;

            case R.id.textview_help:
                Snackbar.make(mTexHelp, "暂不支持", Snackbar.LENGTH_LONG).show();
                mClickCount--;
                if (mClickCount <= 0) {
                    mClickCount = 7;
                    Toast.makeText(ActivityAbout.this, getVersion(), Toast.LENGTH_LONG).show();
                }
                break;

            case R.id.toolbar_back:
                finish();
                break;

            default:
                break;
        }
    }

    private String getVersion() {
        String version = "当前版本：V1.0.0";
        try {
            PackageManager manager = getPackageManager();
            PackageInfo info = manager.getPackageInfo(getPackageName(), 0);
            version = "当前版本：V" + info.versionName + "." + info.versionCode;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return version;
    }
}
